home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / security / wuser / username.frm < prev    next >
Text File  |  1995-10-11  |  9KB  |  248 lines

  1. VERSION 2.00
  2. Begin Form ChG_UserName 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "'Secret' Windows Access"
  5.    ClipControls    =   0   'False
  6.    ControlBox      =   0   'False
  7.    Height          =   2460
  8.    Icon            =   USERNAME.FRX:0000
  9.    Left            =   1050
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2055
  13.    ScaleWidth      =   4275
  14.    Top             =   1395
  15.    Width           =   4395
  16.    Begin CommandButton cmd 
  17.       Caption         =   "&OK"
  18.       Height          =   315
  19.       Left            =   3420
  20.       TabIndex        =   6
  21.       Top             =   1560
  22.       Width           =   675
  23.    End
  24.    Begin TextBox Text 
  25.       FontBold        =   0   'False
  26.       FontItalic      =   0   'False
  27.       FontName        =   "MS Sans Serif"
  28.       FontSize        =   8,25
  29.       FontStrikethru  =   0   'False
  30.       FontUnderline   =   0   'False
  31.       Height          =   285
  32.       HideSelection   =   0   'False
  33.       Index           =   2
  34.       Left            =   2280
  35.       MousePointer    =   1  'Arrow
  36.       TabIndex        =   2
  37.       Top             =   1575
  38.       Width           =   915
  39.    End
  40.    Begin TextBox Text 
  41.       FontBold        =   0   'False
  42.       FontItalic      =   0   'False
  43.       FontName        =   "MS Sans Serif"
  44.       FontSize        =   8,25
  45.       FontStrikethru  =   0   'False
  46.       FontUnderline   =   0   'False
  47.       Height          =   285
  48.       HideSelection   =   0   'False
  49.       Index           =   1
  50.       Left            =   180
  51.       MousePointer    =   1  'Arrow
  52.       TabIndex        =   1
  53.       Top             =   1080
  54.       Width           =   3915
  55.    End
  56.    Begin TextBox Text 
  57.       FontBold        =   0   'False
  58.       FontItalic      =   0   'False
  59.       FontName        =   "MS Sans Serif"
  60.       FontSize        =   8,25
  61.       FontStrikethru  =   0   'False
  62.       FontUnderline   =   0   'False
  63.       Height          =   285
  64.       HideSelection   =   0   'False
  65.       Index           =   0
  66.       Left            =   180
  67.       MousePointer    =   1  'Arrow
  68.       TabIndex        =   0
  69.       Top             =   420
  70.       Width           =   3915
  71.    End
  72.    Begin Label Label1 
  73.       Caption         =   "&True Windows Version:"
  74.       Height          =   195
  75.       Index           =   2
  76.       Left            =   180
  77.       TabIndex        =   5
  78.       Top             =   1620
  79.       Width           =   1980
  80.    End
  81.    Begin Label Label1 
  82.       Caption         =   "&Company Name:"
  83.       Height          =   195
  84.       Index           =   1
  85.       Left            =   180
  86.       TabIndex        =   4
  87.       Top             =   840
  88.       Width           =   1380
  89.    End
  90.    Begin Label Label1 
  91.       Caption         =   "&User Name:"
  92.       Height          =   195
  93.       Index           =   0
  94.       Left            =   180
  95.       TabIndex        =   3
  96.       Top             =   180
  97.       Width           =   1005
  98.    End
  99. End
  100. '                                                         '
  101. '  *****************************************************  '
  102. '  This example demonstrates how to access the UserName,  '
  103. '      the CompanyName and the true Windows version.      '
  104. '  *****************************************************  '
  105. '                                                         '
  106. '    For more details see USERNAME.HLP which should be    '
  107. '     contained as well in this archive (WUSER.EXE).      '
  108. '                                                         '
  109. '     If you have further questions e-mail the author     '
  110. '                directly via CompuServe.                 '
  111. '                                                         '
  112. '                  Christian Germelmann                   '
  113. '                     Am Glaskopf 26                      '
  114. '                   35039 Marburg/Lahn                    '
  115. '                        Germany                          '
  116. '                  Phone +49 6421 45457                   '
  117. '                 CompuServe 100520,2644                  '
  118. '                                                         '
  119. '  Disclaimer: the author will not be responsible for any '
  120. '              misuse of this sample code !               '
  121. '                                                         '
  122. Option Explicit
  123.  
  124. Dim retInt%     ' holds an Integer variable '
  125. Dim retLng&     ' holds a Long variable     '
  126.  
  127. ' *****************************************************************
  128. ' * The declarations for disabling the editing of the text boxes: *
  129. ' *****************************************************************
  130.  
  131. Declare Function SendMessage& Lib "USER" Alias "#111" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, lParam As Any)
  132. Const WM_USER& = &H400
  133. Const EM_SETREADONLY& = (WM_USER + 31)
  134.  
  135.  
  136. ' ************************************************
  137. ' * The API declarations to the 'secret access': *
  138. ' ************************************************
  139.  
  140. Declare Function GetModuleHandle% Lib "KERNEL" Alias "#47" (ByVal lpModuleName$)
  141. Declare Function LoadString% Lib "USER" Alias "#176" (ByVal hInstance%, ByVal wID%, ByVal lpBuffer As Any, ByVal nBufferMax%)
  142.  
  143. ' --> Correct numbers for the Alias-declarations '
  144. '     can e.g. be achived with the author's      '
  145. '     program APIMAN.EXE.                        '
  146.  
  147. Sub cmd_Click ()
  148.  
  149.     Unload Me
  150.  
  151. End Sub
  152.  
  153. Function CompanyName$ ()
  154.  
  155.     CompanyName = GetUserString(515)
  156.  
  157. End Function
  158.  
  159. Sub Form_Load ()
  160.  
  161.     ' *****************************************
  162.     ' Fill the text boxes with the desired data
  163.     ' *****************************************
  164.     Text(0) = UserName()
  165.     Text(1) = CompanyName()
  166.     Text(2) = TrueWinVer()
  167.     
  168.     ' *********************************
  169.     ' Make the text boxes 'untouchable'
  170.     ' *********************************
  171.     retLng = SendMessage(Text(0).hWnd, EM_SETREADONLY, True, 0)
  172.     retLng = SendMessage(Text(1).hWnd, EM_SETREADONLY, True, 0)
  173.     retLng = SendMessage(Text(2).hWnd, EM_SETREADONLY, True, 0)
  174.     
  175.     ' ************************
  176.     ' Place the form on screen
  177.     ' ************************
  178.     Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2.5
  179.     
  180.     Show
  181.  
  182. End Sub
  183.  
  184. '                                                                 '
  185. ' This is the function that returns a string from the USER.EXE.   '
  186. ' To access other loaded (!) modules exchange "USER" against the  '
  187. ' other module's name and select a string number.                 '
  188. '                                                                 '
  189. ' In the USER.EXE we e.g. find:                                   '
  190. '   514  the UserName                                             '
  191. '   515  the CompanyName                                          '
  192. '   516  the true Windows version                                 '
  193. '   518  the serial number                                        '
  194. '                                                                 '
  195. ' and for multilingual purposes:                                  '
  196. '    85  'Cancel'                                                 '
  197. '    86  '&Abort'                                                 '
  198. '    87  '&Retry'                                                 '
  199. '    88  '&Ignore'                                                '
  200. '    89  '&Yes'                                                   '
  201. '    90  '&No'                                                    '
  202. '    78  'Error'                                                  '
  203. ' --> All in the respective language of a country !               '
  204. ' --> Use them for international labeling !                       '
  205. '                                                                 '
  206. Function GetUserString$ (StringNumber%)
  207.  
  208. Dim ReturnedString$
  209.  
  210.     ' ********************************* '
  211.     ' The maximum length of a string at '
  212.     ' that location is 30 characters.   '
  213.     ' So we preload only 30 spaces.     '
  214.     ' ********************************* '
  215.     ReturnedString = Space(30)
  216.     retInt = LoadString(GetModuleHandle("USER"), StringNumber, ReturnedString, Len(ReturnedString))
  217.     
  218.     ' ********************************************************* '
  219.     ' We actually do not need this now but when accessing other '
  220.     ' strings for a mulilingual purpose we should keep it here. '
  221.     ' ********************************************************* '
  222.     ReturnedString = (Left$(ReturnedString, retInt))
  223.  
  224. GetUserString = Trim$(ReturnedString)
  225.  
  226. End Function
  227.  
  228. Sub Text_Change (Index As Integer)
  229.  
  230.     Text(Index).SelStart = 0
  231.     Text(Index).SelLength = 30
  232.     DoEvents
  233.  
  234. End Sub
  235.  
  236. Function TrueWinVer$ ()
  237.  
  238.     TrueWinVer = GetUserString(516)
  239.  
  240. End Function
  241.  
  242. Function UserName$ ()
  243.  
  244.     UserName = GetUserString(514)
  245.  
  246. End Function
  247.  
  248.